package com.yj.cloudnote.service.Impl;

import com.yj.cloudnote.dao.UserMapper;
import com.yj.cloudnote.model.Page;
import com.yj.cloudnote.model.User;
import com.yj.cloudnote.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: jy
 * @Description:
 * @Date: 10:48 2018/4/8
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getAllUsers() {
        return userMapper.selectAll();
    }

    @Override
    public User selectByPrimaryKey(Integer userid) {
        return userMapper.selectByPrimaryKey(userid);
    }

    @Override
    public User selectByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    @Override
    public void insertUser(User user) {
        userMapper.insertSelective(user);
    }

    @Override
    public List<User> getUsersByPage(Page page) {
        HashMap<String,Object> params = new HashMap<String,Object>();
        params.put("start",page.getStart());
        params.put("end",page.getEnd());
        return userMapper.selectUsersByPage(params);
    }

    @Override
    public int getUnblockedCount() {
        return userMapper.getUnblockedCount();
    }

    @Override
    public Boolean userBlocked(int userid) {
        if (userMapper.blocked(userid) >= 0) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public List<User> getBlockedUsersByPage(Page page) {
        HashMap<String,Object> params = new HashMap<String,Object>();
        params.put("start",page.getStart());
        params.put("end",page.getEnd());
        return userMapper.selectBlockedUsersByPage(params);
    }

    @Override
    public int getBlockedCount() {
        return userMapper.getBlockedCount();
    }

    @Override
    public Boolean userUnblocked(int userid) {
        if (userMapper.unblocked(userid) >= 0) {
            return true;
        } else {
            return false;
        }

    }
}
